# This is a sample Python script.
import os

import myakshare
import mysqlUtils


# Press Shift+F10 to execute it or replace it with your code.
# Press Double Shift to search everywhere for classes, files, tool windows, actions, and settings.


def print_hi(name):
    # Use a breakpoint in the code line below to debug your script.
    print(f'Hi, {name}')  # Press Ctrl+F8 to toggle the breakpoint.


def traverse_windows_directory(directory):
    codelist =  set()
    for root, dirs, files in os.walk(directory):
        print(f"Directory: {root}")
        for dir_name in dirs:
            print(f"\tSubdirectory: {os.path.join(root, dir_name)}")
        for file_name in files:
            # print(f"\tFile: {os.path.join(root, file_name)}")
            # print(file_name[2:8])
            # print(file_name[2:8])
            codelist.add(file_name[2:8])
    print( len(codelist) )
    return codelist


# Press the green button in the gutter to run the script.
if __name__ == '__main__':
    print_hi('PyCharm')
    # szcodelist = traverse_windows_directory(r"D:\sharestock\new_tdx\vipdoc\sz\lday")
    # shcodelist = traverse_windows_directory(r"D:\sharestock\new_tdx\vipdoc\sh\lday")
    # codelist = set.union( szcodelist,shcodelist )
    # codelist = szcodelist | shcodelist
    # print(len(codelist))
    # print(codelist)

    try:
        data = myakshare.get_spotDataInsertDb()
        # print(data)
        # print(len(data))
        for element in data:
            try:
                # print(element)
                myakshare.get_cmdata(element)
                # break
            except Exception as e:
                print("__main__================Error get_cmdata:", e)
    except Exception as e:
        print("__main__================Error get_spotDataInsertDb:", e)


    # for element in codelist:
    #     print(element)
    #     try:
    #         myakshare.get_cmdata(element)
    #         break
        # except Exception as e:
        #     print("__main__================Error occurred:", e)
    print("========__main__=======处理完成==============")
        # break


